const Service = require("egg").Service;

class UserService extends Service {
    /**
     * 根据用户名查找指定用户
     * @param {string} username 用户名
     */
    async findByUsername(username) {
        let sql = "select * from user where username = ?";
        let params = [username];
        let res = await this.app.mysql.query(sql, params);
        return res[0];
    }

    /**
     * 添加用户
     * @param {*} username
     * @param {*} password
     * @param {*} nickname
     */
    async addUser(username, password, nickname) {
        let sql =
            "insert into user (username, password, nickname) values (?, ?, ?)";
        let params = [username, password, nickname];
        let res = await this.app.mysql.query(sql, params);
        return res;
    }
}

module.exports = UserService;
